package com.ruoyi.web.controller.background;

import com.ruoyi.background.domain.AppCompanyRules;
import com.ruoyi.background.service.IAppCompanyRulesService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 规章制度Controller
 *
 * @author susu
 * @date 2024-08-05
 */
@RestController
@RequestMapping("/applet/companyRules")
public class AppCompanyRulesController extends BaseController {
    @Autowired
    private IAppCompanyRulesService appCompanyRulesService;

    /**
     * 查询规章制度列表
     */
    @PreAuthorize("@ss.hasPermi('applet:companyRules:list')")
    @GetMapping("/list")
    public TableDataInfo list(AppCompanyRules appCompanyRules) {
        startPage();
        List<AppCompanyRules> list = appCompanyRulesService.selectAppCompanyRulesList(appCompanyRules);
        return getDataTable(list);
    }

    /**
     * 导出规章制度列表
     */
    @PreAuthorize("@ss.hasPermi('applet:companyRules:export')")
    @Log(title = "规章制度", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AppCompanyRules appCompanyRules) {
        List<AppCompanyRules> list = appCompanyRulesService.selectAppCompanyRulesList(appCompanyRules);
        ExcelUtil<AppCompanyRules> util = new ExcelUtil<AppCompanyRules>(AppCompanyRules.class);
        util.exportExcel(response, list, "规章制度数据");
    }

    /**
     * 获取规章制度详细信息
     */
    @PreAuthorize("@ss.hasPermi('applet:companyRules:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(appCompanyRulesService.selectAppCompanyRulesById(id));
    }

    /**
     * 新增规章制度
     */
    @PreAuthorize("@ss.hasPermi('applet:companyRules:add')")
    @Log(title = "规章制度", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AppCompanyRules appCompanyRules) {
        return toAjax(appCompanyRulesService.insertAppCompanyRules(appCompanyRules));
    }

    /**
     * 修改规章制度
     */
    @PreAuthorize("@ss.hasPermi('applet:companyRules:edit')")
    @Log(title = "规章制度", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AppCompanyRules appCompanyRules) {
        return toAjax(appCompanyRulesService.updateAppCompanyRules(appCompanyRules));
    }


    /**
     * 修改规章制度状态
     */
    @PreAuthorize("@ss.hasPermi('applet:companyRules:edit')")
    @Log(title = "规章制度", businessType = BusinessType.UPDATE)
    @GetMapping("/changeStatus/{id}/{status}")
    public AjaxResult editStatus(@PathVariable Long id, @PathVariable Integer status) {
        return toAjax(appCompanyRulesService.changeStatus(id, status));
    }

    /**
     * 删除规章制度
     */
    @PreAuthorize("@ss.hasPermi('applet:companyRules:remove')")
    @Log(title = "规章制度", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(appCompanyRulesService.deleteAppCompanyRulesByIds(ids));
    }
}
